package cnpm.dao.impl;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import cnpm.dao.NationalityDAO;
import cnpm.entity.Nationality;
import cnpm.util.HibernateUtil;

public class NationalityDAOImpl implements NationalityDAO {

	private SessionFactory sessionFactory;
	private Session session;
	
	public NationalityDAOImpl() {
		sessionFactory = HibernateUtil.getSessionFactory();
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Nationality> getAllNationality() {
		List<Nationality> list=null;
		try{
			session = sessionFactory.openSession();
			list = (List<Nationality>) session.createCriteria(Nationality.class).list();
		}catch(HibernateException e){
			e.printStackTrace();
		}finally{
			session.close();
		}
		return list;
	}

	@Override
	public Nationality getNationalityByID(int NationalityID) {
		Nationality d =null;
		try{
			session = sessionFactory.openSession();
			d = (Nationality) session.get(Nationality.class, NationalityID);
		}catch(HibernateException e){
			e.printStackTrace();
		}finally{
			session.close();
		}
		return d;
	}

}
